package com.softcits.hw;

import java.util.Arrays;
import java.util.Date;

import org.apache.commons.mail.EmailException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.softcits.hw.ioc.Person;
import com.softcits.hw.model.MailInfo;
import com.softcits.hw.service.EmailService;

public class HelloWorldApplication {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = 
                new AnnotationConfigApplicationContext(HelloWorldConfig.class);
        
        EmailService service = ctx.getBean(EmailService.class);
        
        System.out.println(service);
        
        MailInfo info = new MailInfo();
        info.setSubject("SoftCITS Email Study!");
        info.setContent("<h1>Welcome to Softcits! </h1><br/>We are learning Email");
        
        String [] toArr = {
                "809341107@qq.com",
                "334794104@qq.com",
        };
        
        info.setToAddress(Arrays.asList(toArr));
        try {
            service.sendEmail(info);
        } catch (EmailException e) {
            e.printStackTrace();
        }
        
        System.out.println("Done.");
        
//        ctx.register(HelloWorldConfig.class);
//        ctx.refresh();
//        HelloWorld hw = ctx.getBean(HelloWorld.class);
//        
//        hw.sayHello();
//        boolean b = ctx.isSingleton("hw");
//        System.out.println(b);
//        
//        Date date = ctx.getBean(Date.class);
//        System.out.println(date);
//        
//        EmailInfo ei = ctx.getBean(EmailInfo.class);
//        System.out.println(ei);
//        
//        Person person = ctx.getBean(Person.class);
//        System.out.println("first person: " + person);
//        person = ctx.getBean(Person.class);
//        System.out.println("scecod person: " + person);
//        
//        HelloWorldConfig conf = ctx.getBean(HelloWorldConfig.class);
//        
//        conf.outputProperties();
        
        
//        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
//        HelloWorld hw = (HelloWorld) ctx.getBean("hw");
//        hw.sayHello();
//        
//        HelloWorld hw2 = ctx.getBean(HelloWorld.class);
//        hw2.sayHello();
//        
//        Set<Object> set = (Set<Object>) ctx.getBean("myset");
//        
//        set.add(1);
//        set.add(2);
//        set.add(1);
//        set.add(3);
//        set.add(4);
//        System.out.println(set);

    }

}
